
package net.neiquan.applibrary.wight;

import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.zxc.layout.autolayout.AutoLayoutActivity;
import com.zxc.layout.autolayout.util.ScreenUtils;

import net.neiquan.applibrary.utils.PixelUtil;

public class SwipeBackActivity extends AutoLayoutActivity implements SwipeBackActivityBase, ActivityCompat.OnRequestPermissionsResultCallback,SwipeBackActivityHelper.CallBackScll {
    private SwipeBackActivityHelper mHelper;
    public boolean isSwipe = true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mHelper = new SwipeBackActivityHelper(this);
        mHelper.setCallBackScll(this);
        mHelper.onActivityCreate();
        if(isSwipe){
            mHelper.getSwipeBackLayout().setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
        }else {
            mHelper.getSwipeBackLayout().setEdgeTrackingEnabled(SwipeBackLayout.STATE_IDLE);
        }

        mHelper.getSwipeBackLayout().setEdgeSize(PixelUtil.getScreenWidth(this));
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        mHelper.onPostCreate();
    }

    @Override
    public View findViewById(int id) {
        View v = super.findViewById(id);
        if (v == null && mHelper != null)
            return mHelper.findViewById(id);
        return v;
    }

    @Override
    public SwipeBackLayout getSwipeBackLayout() {
        return mHelper.getSwipeBackLayout();
    }

    @Override
    public void setSwipeBackEnable(boolean enable) {
        getSwipeBackLayout().setEnableGesture(enable);
    }

    @Override
    public void scrollToFinishActivity() {
        Utils.convertActivityToTranslucent(this);
        getSwipeBackLayout().scrollToFinishActivity();
    }

    @Override
    public void callBackScll(int edgeFlag) {

    }
}
